home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / src / mouse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  4.2 KB  |  191 lines

  1. /* Mouse managing
  2.    Copyright (C) 1994 Miguel de Icaza.
  3.    
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2 of the License, or
  7.    (at your option) any later version.
  8.    
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* Events received by clients of this library have their coordinates 0 */
  19. /* based */
  20.  
  21. /* "$Id: mouse.c,v 1.8 1995/02/21 19:06:52 miguel Exp $" */
  22.  
  23. #include <config.h>
  24. #include <sys/types.h>
  25. #ifdef HAVE_UNISTD_H
  26. #   include <unistd.h>
  27. #endif
  28. #include <signal.h>    /* For kill() and SIGQUIT */
  29. #include <fcntl.h>
  30. #include <termios.h>
  31. #include <malloc.h>
  32. #include <stdio.h>
  33.  
  34. #include "mad.h"
  35. #include "mouse.h"
  36. #include "global.h"        /* ESC_STR */
  37. #include "util.h"        /* xmalloc */
  38. #include "key.h"        /* define sequence */
  39.  
  40. int xmouse_flag = 0;
  41.  
  42. #ifdef HAVE_LIBGPM
  43. static int mouse_d;        /* Handle to the mouse server */
  44. static int console_fd;        /* Handle to the console */
  45. #endif
  46.  
  47. #ifdef DEBUGMOUSE
  48. /* Only used for debugging */
  49. static int top_event = 0;
  50. FILE *log;
  51. #endif
  52.  
  53. #ifdef HAVE_LIBGPM
  54.  
  55. void show_mouse_pointer (int x, int y)
  56. {
  57. #ifdef HAVE_LIBGPM
  58.     if (use_mouse_p == GPM_MOUSE){
  59.     Gpm_DrawPointer (x, y, console_fd);
  60.     }
  61. #endif
  62. }
  63.  
  64. #endif /* HAVE_LIBGPM */
  65. #if 0
  66. int mouse_handler (Gpm_Event *gpm_event)
  67. {
  68.     MouseEvent *event = mouse_events;
  69.     int x = last_x = gpm_event->x;
  70.     int y = last_y = gpm_event->y;
  71.     int redo = 0;
  72.     
  73. /*    DEBUGM ((log, "Mouse [%d, %d]\n", x, y)); */
  74.  
  75.     /* Call any registered event handlers */
  76.     for (; event; event = (MouseEvent *) event->next){
  77.     if ((event->x1 <= x) && (x <= event->x2)
  78.         && (event->y1 <= y) && (y <= event->y2)){
  79.         gpm_event->x -= event->x1;
  80.         gpm_event->y -= event->y1;
  81.         last_mouse_event = event;
  82.         redo = (*(event->mouse_callback))(gpm_event, event->data);
  83.         gpm_event->x += event->x1;
  84.         gpm_event->y += event->y1;
  85.         break;
  86.     }
  87.     }
  88.     return redo;
  89. }
  90.  
  91. int redo_mouse (Gpm_Event *event)
  92. {
  93.     if (last_mouse_event){
  94.         int result;
  95.         event->x -= last_mouse_event->x1;
  96.         event->y -= last_mouse_event->y1;
  97.     result = (*(last_mouse_event->mouse_callback))
  98.              (event,last_mouse_event->data);
  99.         event->x += last_mouse_event->x1;
  100.         event->y += last_mouse_event->y1;
  101.         return result;
  102.     }
  103.     return MOU_NORMAL;
  104. }
  105. #endif
  106.  
  107. void init_mouse (void)
  108. {
  109.     switch (use_mouse_p)
  110.     {
  111. #ifdef HAVE_LIBGPM
  112.       case GPM_MOUSE:
  113.     {
  114.         Gpm_Connect conn;
  115.  
  116.         conn.eventMask   = ~GPM_MOVE;
  117.         conn.defaultMask = GPM_MOVE;
  118.         conn.minMod      = 0;
  119.         conn.maxMod      = 0;
  120.  
  121.         if ((console_fd = open("/dev/console", O_WRONLY)) == -1)
  122.             return;
  123.  
  124.         if ((mouse_d = Gpm_Open (&conn, 0)) == -1)
  125.             return;
  126.  
  127. #ifdef DEBUGMOUSE
  128.         log = fopen ("mouse.log", "w");
  129. #endif
  130.     }
  131.     break;
  132. #endif /* HAVE_LIBGPM */
  133.     case XTERM_MOUSE:
  134.         if (!xmouse_flag) {
  135.  
  136.         /* save old highlight mouse tracking */
  137.         printf("%c[?1001s",27);
  138.  
  139.         /* enable mouse tracking */
  140.         printf("%c[?1000h",27);
  141.  
  142.         fflush (stdout);
  143.         /* turn on */
  144.         xmouse_flag = 1; 
  145.         define_sequence (0, ESC_STR "[M", MCKEY_NOACTION);
  146.         }
  147.         break;
  148.     default:
  149.         /* nothing */
  150.     break;
  151.     } /* switch (use_mouse_p) */ 
  152. }
  153.  
  154. void shut_mouse (void)
  155. {
  156.     switch (use_mouse_p){
  157. #ifdef HAVE_LIBGPM
  158.       case GPM_MOUSE:
  159.     close (console_fd);
  160.     Gpm_Close ();
  161.     break;
  162. #endif
  163.       case XTERM_MOUSE:
  164.     if (xmouse_flag) {
  165.  
  166.         /* disable mouse tracking */
  167.         /* Changed the 1 for an 'l' below: */
  168.         printf("%c[?1000l",27);
  169.  
  170.         /* restore old highlight mouse tracking */
  171.         printf("%c[?1001r",27);
  172.  
  173.         fflush (stdout);
  174.         /* off */
  175.         xmouse_flag = 0;
  176.     }
  177.     break;
  178.       default:
  179.     /* nothing */
  180.     break;
  181.     }
  182. }
  183.  
  184. #ifdef DEBUGMOUSE
  185. void mouse_log (char *function, char *file, int line)
  186. {
  187.     fprintf (log, "%s called from %s:%d\n", function, file, line);
  188. }
  189. #endif
  190.  
  191.